package cn.itcast.usermanage.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import cn.itcast.usermanage.mapper.UserMapper;
import cn.itcast.usermanage.pojo.DataResult;
import cn.itcast.usermanage.pojo.User;

@Service
public class UserService {
	@Autowired
	private UserMapper userMapper;

	/**
	 * 分页查询方法
	 * 
	 * @param page
	 * @param rows
	 * @return
	 */
	public DataResult<User> queryUserListByPage(Integer page, Integer rows) {
		/*
		 * // 查询总条数 Long total = this.userMapper.queryTotalCuont(); // 查询分页数据
		 * List<User> list = this.userMapper.queryUserListByPage((page - 1) *
		 * rows, rows);
		 */

		// 分页：
		PageHelper.startPage(page, rows, true);
		// 查询
		List<User> list = this.userMapper.queryAll();
		// 我们对结果进行解析
		PageInfo<User> info = new PageInfo<>(list);

		// 返回分页数据
		return new DataResult<>(info.getTotal(), list);
	}

	public void saveUser(User user) {
		userMapper.saveUser(user);
		
	}

	public void updateUser(User user) {
		userMapper.updateUser(user);
		
	}

}
